<template>
	<view>
		<view class="title">
			<text>{{wjClassify}}名称</text>
			<span>名称不能为空</span>
		</view>
		<textarea @input="getTitle" class="textarea-top" :placeholder="'在此输入' + wjClassify + '名称'" :value="title"></textarea>
		<view>
			<view class="title-bottom">{{wjClassify}}说明</view>
			<textarea @input="getExplain" class="textarea-bottom" :placeholder="'在此输入' + wjClassify + '说明'" :value="beizhu"></textarea>
		</view>
		<view class="save" @tap="Save">确定</view>
	</view>
</template>

<script>
	import api from "@/common/api.js";
	import {
		baseURL
	} from "@/common/http.js";
	export default {
		data() {
			return {
				title_original: '',
				title: '',
				beizhu: '',
				id: '',
				wjType: '',
				wjClassify: '调查'
			};
		},
		methods: {
			getTitle(e) {
				this.title = e.detail.value
			},
			getExplain(e) {
				this.beizhu = e.detail.value
			},
			Save() {
				let that = this
				if(this.title && this.title != '') {
					let data = {
						api: 'updatec',
						table: '3',
						text: that.beizhu,
						namewenid: that.title,
						id: that.id
					}
					if(this.title_original == data.namewenid) {
						uni.navigateTo({
							url: '../editDiaocha/editDiaocha?wenid=' + this.wenid
						})
					} else {
						api.editSur(data).then(res => {
							if (res.code == 200) {
								uni.navigateTo({
									url: '../editDiaocha/editDiaocha?wenid=' + this.wenid
								})
							} else {
								uni.showToast({
									title: "编辑失败",
									duration: 1000,
									icon: 'none'
								})
							}
						}).catch(err => {
							console.log(err)
						})
					}
				} else {
					uni.showToast({
						title: '问卷标题不能为空',
						icon: 'none',
						duration: 1500
					})
				}
			}
		},
		onShareAppMessage(options) {
			let shareObj = {
				success: (res) => {
					if (res.errMsg == 'shareAppMessage:ok') {
						uni.showToast({
							title: '分享成功',
							icon: 'success',
							duration: 1500
						})
					}
				},
				fail: () => {
					if (res.errMsg == 'shareAppMessage:fail cancel') {
						uni.showToast({
							title: '取消分享',
							icon: 'none',
							duration: 2000
						})
					} else if (res.errMsg == 'shareAppMessage:fail') {
						// 转发失败，其中 detail message 为详细失败信息
					}
				},
				complete: () => {
					// 转发结束之后的回调（转发成不成功都会执行）
				}
			}
		},
		onLoad(options) {
			let that = this
			this.wjType = this.$store.state.wjType
			if(this.wjType == 2) {
				uni.setNavigationBarTitle({
					title: '编辑表单'
				})
				this.wjClassify = '表单'
			} else {
				uni.setNavigationBarTitle({
					title: '编辑调查'
				})
				this.wjClassify = '调查'
			}
			let items = JSON.parse(options.item)
			this.title = items.title
			this.title_original = items.title
			this.wenid = items.wenid
			this.id = items.id
			items.text == "添加问卷说明" ? this.beizhu = "" : this.beizhu = items.text
		}
	}
</script>

<style lang="scss">
	page {
		font-family: PingFang SC;
		font-weight: 500;
	}

	.title {
		width: 690rpx;
		margin: 80rpx auto 20rpx;

		text {
			color: #333;
			font-size: 36rpx;
			margin-right: 10rpx;
		}

		span {
			color: #E60000;
			font-size: 24rpx;
		}
	}

	.placeholder {
		font-size: 32rpx;
		color: #999;
		font-weight: normal;
	}

	.textarea-top,
	.textarea-bottom {
		padding: 20rpx;
		box-sizing: border-box;
		width: 690rpx;
		height: 200rpx;
		margin: 0 auto;
		border: 1rpx solid #999;
		border-radius: 5rpx;
		font-weight: normal;
	}

	.title-bottom {
		width: 690rpx;
		margin: 30rpx auto;
		font-size: 36rpx;
		color: #333;
	}

	.textarea-bottom {
		height: 250rpx;
	}

	.save {
		width: 690rpx;
		height: 100rpx;
		line-height: 100rpx;
		font-size: 36rpx;
		background: #209FFC;
		color: #fff;
		text-align: center;
		border-radius: 50rpx;
		margin: 100rpx auto 0;
	}
</style>
